from pms.common.views import PostFormula, PermissionDeny
from info.models import Notice
from info.utils.notice import notice_view, assert_notice_visible


class API(PostFormula):
    def handle(self, req):
        notice = Notice.objects.get(id=req['id'])
        try:
            assert_notice_visible(self.user, notice)
        except PermissionDeny:
            return self.failed_respond('NOTICE_INVISIBLE', '公告对用户不可见')
        return self.success_respond(notice_view(notice))
